import { defHttp, deployHttp } from '/@/utils/http/axios';
import { ImageDto, ImageInfo, ImageListGetResultModel, ImagePageQueryParams, ImageUpdateDto, isoItem } from './model/imageModel';
import { UploadFileParams } from '/#/axios';

enum Api {
  IMAGE_LIST_BY_APP_COMP = '/v1/image/list',

  IMAGE_UPDATE = '/v1/image/update',
  IMAGE_DELETE = '/v1/image/delete',
  IMAGE_BY_COMPONENT = '/v1/image',
  IMAGE_BY_APP_COMP = '/v1/image/list',
  IMAGE_CREATE = '/v1/image/create',

  IMAGE_UPLOAD = '/basic-api/saaslandingDeployment/v1/image/upload/',

  ISO_ITEMS = '/application/getApplicationItems',
}

export function imageUpload(params: UploadFileParams, onUploadProgress: (progressEvent: ProgressEvent) => void) {
  return deployHttp.uploadFile(
    {
      url: Api.IMAGE_UPLOAD + params.data?.imageId,
      onUploadProgress,
      timeout: 100000,
    },
    params
  );
}

export const createImageMetaInfo = (params: ImageInfo) => {
  return deployHttp.post<string>({ url: Api.IMAGE_CREATE, params });
};

export const getImageListByAppComp = (params: ImagePageQueryParams) => {
  return deployHttp.post<ImageListGetResultModel>({
    url: Api.IMAGE_LIST_BY_APP_COMP,
    params,
  });
};
/* eslint-disable */
export const addImageFile = (params: ImageDto, file: string) => {
  return deployHttp.post<string>({ url: Api.IMAGE_UPLOAD, params });
};
/* eslint-disable */
export const updateImage = (params: ImageUpdateDto) => {
  return deployHttp.post<string>({ url: Api.IMAGE_UPDATE, params });
};

export const deleteImage = (id: string) => {
  return deployHttp.delete<string>({ url: Api.IMAGE_DELETE + '/' + id });
};

export const getImageByComponent = (componentId: string) => {
  return deployHttp.get<ImageInfo[]>({
    url: Api.IMAGE_BY_COMPONENT + '/' + componentId,
  });
};

export const getImageByAppComp = (params: ImagePageQueryParams) => {
  return deployHttp.post<ImageListGetResultModel>({
    url: Api.IMAGE_BY_APP_COMP,
    params,
  });
};

export const getIsoList = () => defHttp.get<isoItem[]>({ url: Api.ISO_ITEMS });
